﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

namespace Assets
{
    public class BallController : MonoBehaviour
    {
        [SerializeField]
        public Dictionary<string, Vector3> des = new Dictionary<string, Vector3>();

        public NavMeshAgent nav;
        void Start()
        {
            Transform t = GameObject.Find("Destinations").transform;
            for (int i = 0; i < t.childCount; i++)
            {
                Transform tt = t.GetChild(i);
                des.Add(tt.gameObject.name, new Vector3(tt.position.x, tt.position.y, tt.position.z));
            }

            nav = gameObject.GetComponent<NavMeshAgent>();
        }
        // Update is called once per frame
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                Application.Quit();
            }

            Vector3 newPos;

            newPos = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            gameObject.transform.position += newPos * 5;

        }



        public void ToDestination(string destination)
        {
            nav.ResetPath();
            nav.destination = des[destination];
        }
    }
}